/* -*- coding: utf-8; tab-width: 4 -*-
vim: ts=4 noet ai */

/**
	Desktopd Rainbow Persona -- Colorful Firefox

	Copyright © 2016  Desktopd Project

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as
	published by the Free Software Foundation, either version 3 of the
	License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.

	@license GPL-3.0+
	@file
*/

'use strict';

/* No dependencies. No module import. */


/**
	Y', Cb, Cr values
	R, G, and B are in [0, 1]
*/
exports.fromRGB = (r, g, b) => [
	16 + 65.481 * r + 128.553 * g + 24.966 * b
	,128 - 37.797 * r - 74.203 * g + 112.0 * b
	,128 + 112.0 * r - 93.786 * g - 18.214 * b
];

/**
	R, G, B values
	Inverse of the above
	Note: Resulting RGB may be out of range
*/
exports.toRGB = (Y, Cb, Cr) => [
	0.00456621 * Y + 0.00625893 * Cr - 0.874202
	,0.00456621 * Y - 0.00153632 * Cb - 0.00318811 * Cr + 0.531668
	,0.00456621 * Y + 0.00791072 * Cb - 1.08563
];

